package k2_oop.p1_classAndObject.demo17;

/**
 * 写一个名为Account的类模拟账户。该类的属性和方法如下图所示
 * 该类包括的属性：账号id，余额 balance，年利率 annualInterestRate；
 * 包含的方法：访问器方法（getter和setter方法），取款方法withdraw()，存款方法deposit()。
 *
 * 提示：在提款方法withdraw中，需要判断用户余额是否能够满足提款数额的要求，如果不能，应给出提示
 */
public class Account {

    //定义属性  id 余额 年利率
    private int id;
    private double balance;
    private double annualInterestRate;

    public Account(int id, double balance, double annualInterestRate) {
        this.id = id;
        this.balance = balance;
        this.annualInterestRate = annualInterestRate;
    }

    /**
     * 取款方法
     * @param amount
     */
    public void withdraw (double amount){
        if(amount>this.balance){
            System.out.println("余额不足，无法取款");
        }else{
            this.balance-=amount;
        }
    }

    /**
     * 存款方法
     * @param amount
     */
    public void deposit (double amount){
        this.balance+=amount;
    }

    /**
     * 用户账户的信息展示
     */
    public void display(){
        System.out.println(this.id+"的当前余额为："+this.balance+",年利率为："+this.annualInterestRate);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public double getAnnualInterestRate() {
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double annualInterestRate) {
        this.annualInterestRate = annualInterestRate;
    }
}
